//Dependencies TBD properly
//GENERAL_OPTIONS
//GENERAL HELPERS
(function (that) {

	//local Link to Global-Object or throw Exception
	if(!that){throw "Global object missing, bitchesss";}
	var that = that;

	//Array to store URI-Related parameters
	that.uri_parameters = [];

	//local options object
	var options= {
		//Parameter to be checked in URL
		check_parameters: [
			//Google Analytics GA Parameter
			'utm_source',
			'utm_medium',
			'utm_campaign',
			'utm_term',
			'utm_content'
		],
		check_top: true
	};

	//Merge local options and global options
	//Global options will override local options
	options = that.get_global_options(options);

	//the referrer
	var referrer = window.document.referrer

	//the current location of the Top
	, href = options.check_top ? top.location.href : window.location.href

	//the parameters to check for
	, check_parameters = that.options.check_parameters

	//function to push parameters to param stack
	, push_parameter = function(param, value){
		that.uri_parameters.push([param,value].join('|'));
	};


	//extract all parameters, if false set empty string
	//THIS NEEDS REWORKING !!! WHEN TO CHECK WHICH URL FOR WHICH PARAMETER
	for(var i=0, len = check_parameters.length; i<len; i++){
		push_parameter(check_parameters[i], (that.extract_parameter(referrer)
								||that.extract_parameter(href)
								||'') );
	}

	//push referrer to stack
	push_parameter("ref", referrer);

})(sauberfant);
